package com.nuoyuan.wx.service.helper;

import com.nuoyuan.wx.common.utils.DateUtil;
import com.nuoyuan.wx.dao.po.BookPo;
import com.nuoyuan.wx.vo.BookVo;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Package com.nuoyuan.wx.service.helper
 * @ClassName BookBeanHelper
 * @Description TODO
 * @Author linus
 * @Date 2020-02-25 19:34
 * @Version 1.0
 **/
public class BookBeanHelper {
    public static BookVo toVo(BookPo po) {
        BookVo vo = new BookVo();
        vo.setStartAmount(po.getStartAmount());
        vo.setExpireationMonth(po.getExpireationMonth());
        vo.setAnnualYield(po.getAnnualYield());
        vo.setAppointmentAmount(po.getAppointmentAmount());
        vo.setProductName(po.getProductName());
        vo.setProductNo(po.getProductNo());
        vo.setBookId(po.getBookId());
        vo.setBookType(po.getBookType());
        vo.setCreateTime(DateUtil.formatDate(po.getCreateTime(), DateUtil.FMT_DATE_YYYYMMDD_HHMMSS));
        vo.setIdNo(po.getIdNo());
        vo.setPhone(po.getPhone());
        vo.setProductId(po.getProductId());
        vo.setRealName(po.getRealName());
        vo.setSms(po.getIsSms());
        vo.setUpdateTime(DateUtil.formatDate(po.getUpdateTime(), DateUtil.FMT_DATE_YYYYMMDD_HHMMSS));
        vo.setUserId(po.getUserId());
        return vo;
    }

    public static List<BookVo> toVos(List<BookPo> pos) {
        if(CollectionUtils.isEmpty(pos)) {
            return new ArrayList<>();
        }

        List<BookVo> vos = new ArrayList<>();
        for(BookPo po : pos) {
            vos.add(toVo(po));
        }
        return vos;
    }
}
